﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WLYT.Application.Interfaces;
using WLYT.Domain.Model;
using WLYT.Repository;

namespace WLYT.Application.Services
{
    public class DataBaseLogService : BaseService<DataBaseLog>, IDataBaseLogService
    {
        public ISqlSugarRepository<DataBaseLog> DataBaseLogRepository;
        public DataBaseLogService(ISqlSugarRepository<DataBaseLog> dataBaseLogRepository) : base(dataBaseLogRepository)
        {
            DataBaseLogRepository = dataBaseLogRepository;
        }

        public async Task<Tuple<IList<DataBaseLog>, int>> GetModelsByPageAsync(DateTime? time, string search, int pageSize, int pageIndex)
        {
            Expressionable<DataBaseLog> exp = Expressionable.Create<DataBaseLog>();
            exp.AndIF(time != null, p => SqlFunc.Between(p.CreateTime, time, (time ?? DateTime.Now).AddDays(1)));
            exp.AndIF(!string.IsNullOrEmpty(search), p => p.Sql.Contains(search) || p.Param.Contains(search));
            return await GetPageListAsync(exp, pageSize, pageIndex, p => p.Id);
        }
    }
}
